package com.lsu.proxy.experiment;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

/**
 * DOM4J的测试类
 *
 * @Author wang suo
 * @Date 2020/12/31 0031 9:24
 * @Version 1.0
 */
public class Dom4JTest {
    public static void main(String[] args) {
        SAXReader reader = new SAXReader();
        Document document;
        try {
            document = reader.read(new File("D:\\02文档\\01文档\\大三作业和文件\\设计模式\\代码\\design-patterns\\src\\main\\resources\\config.xml"));
            Element root = document.getRootElement();
            // proxy 节点
            List<Element> allProxy = root.elements();
            // 所有的 proxy 节点
            for (Element proxy : allProxy) {
                Attribute className = proxy.attribute("class");
                Attribute proxyId = proxy.attribute("id");
                String idText = proxyId.getText();
                String classNameText = className.getText();
                System.out.println("classNameText = " + classNameText);
                System.out.println("idText = " + idText);
                List<Element> proxyElements = proxy.elements();

                for (Element proxyElement : proxyElements) {
                    // element 是 method
                    List<Element> methodElements = proxyElement.elements();

                    for (Element methodElement : methodElements) {
                        System.out.println("bean = " + methodElement.attribute("bean").getText());
                        System.out.println("mtd = " + methodElement.attribute("mtd").getText());
                    }
                }
            }
        } catch (DocumentException e) {
            e.printStackTrace();
        }
    }
}
